﻿<UserControl
    x:Class="Markup.Programming.Samples.StateSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="http://markupprogramming.codeplex.com/markup/programming"
    Height="300" Width="300">
    <Grid>
        <StackPanel>
            <Grid Background="AntiqueWhite">
                <TextBlock Margin="4" TextWrapping="Wrap">
                This sample demonstrates that each collection of attached
                operations shares a dictionary of state variables that persist
                between handler executions.  You can initialize variables when
                you are attached to the associated object, manipulate them in
                one or more handlers and report them in another.  If you don't
                want this behavior just create a new scope, e.g. with p:Block.
                </TextBlock>
            </Grid>
            <TextBlock FontSize="20" FontWeight="Bold" TextWrapping="Wrap" Foreground="Beige">
                Left click a few times, then right click.
                <p:Attached.Operations>
                    <p:ScriptHandler Path="@Attached">
                        var $clicks = 0;
                    </p:ScriptHandler>
                    <p:ScriptHandler Path="MouseLeftButtonDown" SetHandled="True">
                        $clicks++;
                    </p:ScriptHandler>
                    <p:ScriptHandler Path="MouseRightButtonDown">
                        [MessageBox].Show([String].Format("Total clicks: {0}", $clicks));
                    </p:ScriptHandler>
                </p:Attached.Operations>
            </TextBlock>
        </StackPanel>
    </Grid>
</UserControl>
